{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8692ba32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "str_eight = str(8)\n",
    "print(type(str_eight))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6741c8fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c365d1cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[i for i in range(5)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "61d1a51f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "liuyanglist = [i for i in range(5)]\n",
    "for entity in liuyanglist: \n",
    "    print(entity)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7bf1dd8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print(i)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a16d0336",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "array = [i for i in range(10)]\n",
    "print(array)\n",
    "print(type(array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "732c483b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n",
      "<class 'numpy.ndarray'>\n",
      "[ 1  2  3  4  5  6  7  8  9 10]\n"
     ]
    }
   ],
   "source": [
    "array = np.array([i for i in range(10)])\n",
    "print(array)\n",
    "print (type(array))\n",
    "array += 1\n",
    "print(array)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9ecab5fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 0.06346652, 0.12693304, 0.19039955, 0.25386607,\n",
       "       0.31733259, 0.38079911, 0.44426563, 0.50773215, 0.57119866,\n",
       "       0.63466518, 0.6981317 , 0.76159822, 0.82506474, 0.88853126,\n",
       "       0.95199777, 1.01546429, 1.07893081, 1.14239733, 1.20586385,\n",
       "       1.26933037, 1.33279688, 1.3962634 , 1.45972992, 1.52319644,\n",
       "       1.58666296, 1.65012947, 1.71359599, 1.77706251, 1.84052903,\n",
       "       1.90399555, 1.96746207, 2.03092858, 2.0943951 , 2.15786162,\n",
       "       2.22132814, 2.28479466, 2.34826118, 2.41172769, 2.47519421,\n",
       "       2.53866073, 2.60212725, 2.66559377, 2.72906028, 2.7925268 ,\n",
       "       2.85599332, 2.91945984, 2.98292636, 3.04639288, 3.10985939,\n",
       "       3.17332591, 3.23679243, 3.30025895, 3.36372547, 3.42719199,\n",
       "       3.4906585 , 3.55412502, 3.61759154, 3.68105806, 3.74452458,\n",
       "       3.8079911 , 3.87145761, 3.93492413, 3.99839065, 4.06185717,\n",
       "       4.12532369, 4.1887902 , 4.25225672, 4.31572324, 4.37918976,\n",
       "       4.44265628, 4.5061228 , 4.56958931, 4.63305583, 4.69652235,\n",
       "       4.75998887, 4.82345539, 4.88692191, 4.95038842, 5.01385494,\n",
       "       5.07732146, 5.14078798, 5.2042545 , 5.26772102, 5.33118753,\n",
       "       5.39465405, 5.45812057, 5.52158709, 5.58505361, 5.64852012,\n",
       "       5.71198664, 5.77545316, 5.83891968, 5.9023862 , 5.96585272,\n",
       "       6.02931923, 6.09278575, 6.15625227, 6.21971879, 6.28318531])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "np.zeros((3, 4))\n",
    "\n",
    "np.ones((3, 4))\n",
    "\n",
    "np.random.random((2,3))\n",
    "\n",
    "np.linspace(0, 2*np.pi, 100)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4b565dc5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "array\t entity\t i\t liuyanglist\t np\t str_eight\t \n"
     ]
    }
   ],
   "source": [
    "%who"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ca2c0f2d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Variable      Type       Data/Info\n",
      "----------------------------------\n",
      "array         ndarray    10: 10 elems, type `int32`, 40 bytes\n",
      "entity        int        4\n",
      "i             int        9\n",
      "liuyanglist   list       n=5\n",
      "np            module     <module 'numpy' from 'C:\\<...>ges\\\\numpy\\\\__init__.py'>\n",
      "str_eight     str        8\n"
     ]
    }
   ],
   "source": [
    "%whos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b7cc2cc3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['array', 'entity', 'i', 'liuyanglist', 'np', 'str_eight']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%who_ls"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd278fa6",
   "metadata": {},
   "source": [
    "#### 练习1： 封装函数求闰年"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "46e8e73a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def is_leap(y):\n",
    "    return y % 4 == 0 and y % 100 != 0 or y % 400 == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b1824485",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "is_leap(2032)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1344609",
   "metadata": {},
   "source": [
    "#### 练习2： 封装函数实现冒泡排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e4b41302",
   "metadata": {},
   "outputs": [],
   "source": [
    "def bubble_sort(l):\n",
    "    for i in range(len(l) - 1):\n",
    "        for j in range(len(l) - i - 1):\n",
    "            if l[j]> l[j + 1]:\n",
    "                l[j], l[j+1] = l[j+1], l[j]\n",
    "    return l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e6be16f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 7, 8]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bubble_sort([1, 3, 6, 5, 2, 8, 7, 4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73999ae6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "bac12638",
   "metadata": {},
   "source": [
    "#### HELLO MARKDOWN"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
